package com.itheima.config;

import com.itheima.quartz.MyQuartz;
import org.quartz.*;
import org.quartz.impl.JobDetailImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

//    @Bean
//    public JobDetail printJobDetail(){
//        //绑定具体的工作
//        return JobBuilder
//                .newJob(MyQuartz.class)
//                .storeDurably()
//                .build();
//    }
//
//    @Bean
//    public Trigger printJobTrigger(){
//        ScheduleBuilder schedBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
//        //绑定对应的工作明细
//        return TriggerBuilder.newTrigger().forJob(printJobDetail()).withSchedule(schedBuilder).build();
//    }

    //    定义一个jobDetail,指定具体的工作
    @Bean
    public JobDetail OutputJobDetail() {
        //通过jobBuilder对象创建job
        return JobBuilder
                .newJob(MyQuartz.class)
                .storeDurably()
                .build();

    }

    //定义一个触发器，来绑定工作明细
    @Bean
    public Trigger trigger() {
        ScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
        return TriggerBuilder.newTrigger().forJob(OutputJobDetail()).withSchedule(scheduleBuilder).build();
    }


}











